import pymysql
from PublicUserManage import models

class sql_content(object):
    def conten(self):
        conn = pymysql.Connect(
            host="127.0.0.1",
            port=3306,
            user='root',
            passwd='123456',
            db='data_collection',
            charset='utf8'
        )

        return conn

    def content_cursor(self):
            conn = pymysql.Connect(
                host="127.0.0.1",
                port=3306,
                user='root',
                passwd='123456',
                db='data_collection',
                charset='utf8'
            )

            cursor = conn.cursor()

            return cursor

            # 查询有多少条

    def data_count(self,sql_str):

        con = self.conten()
        sql_count = sql_str
        cursor = con.cursor()
        try:
            cursor.execute(sql_count)
            rs = cursor.fetchone()
            return rs[0]
        except Exception as e:
            print(e)
            con.rollback()
        cursor.close()
        con.close()